<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>错误！</strong>
	无效的合同信息！
</div>
<#else>
<form class="contract-payout-form" action="${request.contextPath}/sub-contract/pay-out" method="post">
	<input type="hidden" name="contract.id" value="${c.id}" />
	<input type="hidden" name="payOut" value="true" />
	<input type="hidden" name="inAccount" value="true">
	<input type="hidden" name="invoice" value="true">
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null">*</span>
							付款金额
						</div>
					</div>
					<input type="text" class="form-control form-data" name="total" placeholder="请输入支出金额">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null">*</span>
							部门/单位
						</div>
					</div>
					<input type="text" class="form-control form-data" name="source" value="${c.otherCompany}" placeholder="请填写收款部门/单位">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null">*</span>
							付款日期
						</div>
					</div>
					<input type="text" class="form-control form-data datetimepicker" data-format="yyyy-MM-dd" data-foot="false" data-time="${.now}" name="time" placeholder="请选择日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">备注</div>
					</div>
					<textarea rows="5" class="form-control form-data" name="remark" placeholder="最多500个汉字"></textarea>
				</div>
			</div>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(function() {
		// 初始化日期控件
		$.suredy.datetimepicker.init();

		$('form.contract-payout-form .btn-submit').on('click', function() {
			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			var form = true;

			// 判断是否为空
			$('form.contract-payout-form .not-null').each(function() {
				var $this = $(this);

				if (!$('.form-data', $this.parents('.input-group')).val()) {
					alert('请正确填写信息，[ * ]为必填项！');
					form = false;
					return false;
				}
			});

			if (!form)
				return false;

			$this.addClass('disabled');

			form = $('form.contract-payout-form');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '记录付款信息失败!');
						$this.removeClass('disabled');
						return false;
					}

					$.suredy.refreshContent('${c.id}', '${pid}', [ '#tab2' ]);

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('记录付款信息失败!\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
